import { _decorator, Component, Node, EventTouch } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('TouchRotateControls')
export class TouchRotateControls extends Component {

    @property(Node) player: Node

    cameraSensitivity: number = 0.2

    radius: number = 10

    start() {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
        this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
    }

    update(deltaTime: number) {

    }

    onTouchStart(EventTouch: EventTouch) {

    }

    onTouchMove(EventTouch: EventTouch) {
        const x = EventTouch.getDeltaX() * this.cameraSensitivity
        const y = EventTouch.getDeltaY() * this.cameraSensitivity

        const eulerAngles2 = this.player.children[2].eulerAngles
        const eulerAngles1 = this.player.children[1].eulerAngles
        eulerAngles2.add3f(y, -x, 0)
        eulerAngles1.add3f(0, -x, 0)
        this.player.children[2].eulerAngles = eulerAngles2
        this.player.children[1].eulerAngles = eulerAngles1
    }

    onTouchEnd(EventTouch: EventTouch) {

    }
}


